<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表白墙</title>
</head>
<body>
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        .container{
            width: 100%;
        }
        h1 {
            text-align: center;
            padding: 30px 0;
        }
        p{
            text-align: center;
            color: coral;
            padding: 10px 5px;
        }
        .row {
            width: 400px;
            height: 50px;
            margin: 0 auto;

            display: flex;
            justify-content: center;
            align-items: center;
        }

        .row span {
            width: 60px;
            font-size: 20px;

        }
        .row input  {
            width: 300px;
            height: 40px;
            line-height: 30px;
            font-size: 20px;
            text-indent: 0.5em;
            outline: none;
        }

        .row #submit{
            width: 400px;
            height: 40px;
            font-size: 20px;
            line-height: 40px;
            margin: 0 auto;
            color: white;
            background-color: cadetblue;
            border: none;
        }

        .row #submit:active{
            background-color: red;
        }

    </style>
    <div class="container"> 
        <h1>表白墙</h1>
        <p>输入后点击提交</p>
        <div class = "row">
            <span>谁：</span>
            <input type="text">
        </div>
        <div class = "row">
            <span>对谁：</span>
            <input type="text">
        </div>
        <div class = "row">
            <span>说：</span>
            <input type="text">
        </div>
        <div class="row">
            <button id="submit">提交</button>
            <!-- <input type="text"> -->
        </div>
    </div>
    <script>
        //点击提交按钮，就弹出内容
        let submitBtn  = document.querySelector('#submit');
        submitBtn.onclik = function(){
            //1.获取到3个input中的内容
            let inputs = document.querySelectorAll('input');
            let from = inputs[0].value;
            let to = inputs[1].value;
            let msg = inputs[2].value;
            if(from == '' || to == '' || msg == ''){
                return;
            }
            //2.生成一个新的div，内容就是input的内容
            let div = document.createElement('div');
            div.innerHTML = from + ' 对 ' + to + ' 说: ' + msg;
            div.className = 'row';
            let container = document.querySelector('.container');
            container.appendChild(div);
            //3.清空输入空
            for(let i = 0;i<inputs.length;i++){
                inputs[i].value = '';
            }
        }
    </script>
</body>
</html>